/*
 * @Descripttion:装修楼层预览入口：H5预览，APP预览，小程序预览
 * @Date: 2022-06-15 10:49:05
 * @LastEditTime: 2023-08-21 20:54:45
 */
import React from 'react'
import { useEffect, useState } from 'react'
import Taro, { RequestTask } from '@tarojs/taro'
import { BuiltInComponents } from '@modules/components'
import { ContainerFloorList } from '@conecli/cone-render/modules'
import INTERFACE from '../../common/INTERFACE'
import { dealShopContentData } from '@conecli/cone-render/_utils'
import './index.scss'

let keycount = 1

// 初始化
const Preview = (props) => {
	const [floorsContent, setFloors] = useState({
		"containers": [],
		"floors": [],
		"pageSet": {}
	});
	const getAllFloors = () => {

		Taro.request({
			url: INTERFACE.floorContent, //仅为示例，并非真实的接口地址
			// data: {
			//   x: '',
			//   y: ''
			// },
			// header: {
			//   'content-type': 'application/json' // 默认值
			// },
			method: 'POST',
			success: function ({data}) {
				if(data){
					if (data.code == 200 && data.data) {
						console.log("floorContent:", data.data)
						keycount++
						setFloors(data.data)
					}
					else if(data.code == 401){
						// 未登录
						window.location.href = `https://passport.jd.com/new/login.aspx?ReturnUrl=${encodeURIComponent(window.location.href)}`
					}
				}
			}
		})

		// 请求楼层数据
		// fetch({ url: INTERFACE.floorContent }).then((data) => {
		// 	if (data && data.code == 200 && data.data) {
		// 		console.log("floorContent:", data.data)
		// 		keycount++
		// 		setFloors(data.data)
		// 	}
		// })
	}
	useEffect(() => {
		getAllFloors()
	}, [])

	const processingData = dealShopContentData(floorsContent, null, true)
	return <ContainerFloorList
		{...props}
		key={keycount}
		builtInComponents={BuiltInComponents}
		containerFloorListData={processingData.shopContentContainerListData}
	/>

}

export default Preview
